﻿
app.factory("Posts", function () {
    return [];
})

app.controller("ngPostsController", function ($scope, $http, $location, Posts, $routeParams) {
    $scope.posts = Posts;
    $scope.currentPage = $routeParams.pageId;

    $scope.gotoPage = function (pageId) {
        $http.get("api/postpage/" + pageId).success(function (data) {
            $scope.posts = data.Posts;
            $scope.currentPage = data.CurrentPage;
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    }

    $scope.prevPage = function () {
        $scope.gotoPage($scope.currentPage - 1);
    }
    $scope.nextPage = function () {
        $scope.gotoPage($scope.currentPage + 1);
    }

    $scope.gotoPage($scope.currentPage);

});

